home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.text;
-
- import com.sun.java.swing.event.DocumentEvent;
- import com.sun.java.swing.event.DocumentListener;
- import com.sun.java.swing.event.EventListenerList;
- import com.sun.java.swing.event.UndoableEditEvent;
- import com.sun.java.swing.event.UndoableEditListener;
- import com.sun.java.swing.event.DocumentEvent.EventType;
- import com.sun.java.swing.undo.CompoundEdit;
- import com.sun.java.swing.undo.UndoableEdit;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.PrintStream;
- import java.io.Serializable;
- import java.util.Dictionary;
- import java.util.Hashtable;
-
- public abstract class AbstractDocument implements Document, Serializable {
- private transient int numReaders;
- private transient Thread currWriter;
- private Dictionary documentProperties;
- protected EventListenerList listenerList;
- private Content data;
- private AttributeContext context;
- private static final String BAD_LOCK_STATE = "document lock failure";
- protected static final String BAD_LOCATION = "document location failure";
- public static final String ParagraphElementName = "paragraph";
- public static final String ContentElementName = "content";
- public static final String SectionElementName = "section";
- public static final String ElementNameAttribute = "$ename";
- static Class class$com$sun$java$swing$event$UndoableEditListener;
- static Class class$com$sun$java$swing$event$DocumentListener;
-
- protected AbstractDocument(Content data) {
- this(data, StyleContext.getDefaultStyleContext());
- }
-
- protected AbstractDocument(Content data, AttributeContext context) {
- this.documentProperties = null;
- this.listenerList = new EventListenerList();
- this.data = data;
- this.context = context;
- }
-
- public void addDocumentListener(DocumentListener listener) {
- EventListenerList var10000 = this.listenerList;
- Class var10001 = class$com$sun$java$swing$event$DocumentListener;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("com.sun.java.swing.event.DocumentListener");
- } catch (ClassNotFoundException var2) {
- throw new NoClassDefFoundError(((Throwable)var2).getMessage());
- }
-
- class$com$sun$java$swing$event$DocumentListener = var10001;
- }
-
- var10000.add(var10001, listener);
- }
-
- public void addUndoableEditListener(UndoableEditListener listener) {
- EventListenerList var10000 = this.listenerList;
- Class var10001 = class$com$sun$java$swing$event$UndoableEditListener;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("com.sun.java.swing.event.UndoableEditListener");
- } catch (ClassNotFoundException var2) {
- throw new NoClassDefFoundError(((Throwable)var2).getMessage());
- }
-
- class$com$sun$java$swing$event$UndoableEditListener = var10001;
- }
-
- var10000.add(var10001, listener);
- }
-
- protected Element createBranchElement(Element parent, AttributeSet a) {
- return new BranchElement(this, parent, a);
- }
-
- protected Element createLeafElement(Element parent, AttributeSet a, int p0, int p1) {
- return new LeafElement(this, parent, a, p0, p1);
- }
-
- public synchronized Position createPosition(int offs) throws BadLocationException {
- return this.data.createPosition(offs);
- }
-
- public void dump(PrintStream out) {
- Element root = this.getDefaultRootElement();
- if (root instanceof AbstractElement) {
- ((AbstractElement)root).dump(out, 0);
- }
-
- }
-
- protected void fireChangedUpdate(DocumentEvent e) {
- Object[] listeners = this.listenerList.getListenerList();
-
- for(int i = listeners.length - 2; i >= 0; i -= 2) {
- Object var10000 = listeners[i];
- Class var10001 = class$com$sun$java$swing$event$DocumentListener;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("com.sun.java.swing.event.DocumentListener");
- } catch (ClassNotFoundException var4) {
- throw new NoClassDefFoundError(((Throwable)var4).getMessage());
- }
-
- class$com$sun$java$swing$event$DocumentListener = var10001;
- }
-
- if (var10000 == var10001) {
- ((DocumentListener)listeners[i + 1]).changedUpdate(e);
- }
- }
-
- }
-
- protected void fireInsertUpdate(DocumentEvent e) {
- Object[] listeners = this.listenerList.getListenerList();
-
- for(int i = listeners.length - 2; i >= 0; i -= 2) {
- Object var10000 = listeners[i];
- Class var10001 = class$com$sun$java$swing$event$DocumentListener;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("com.sun.java.swing.event.DocumentListener");
- } catch (ClassNotFoundException var4) {
- throw new NoClassDefFoundError(((Throwable)var4).getMessage());
- }
-
- class$com$sun$java$swing$event$DocumentListener = var10001;
- }
-
- if (var10000 == var10001) {
- ((DocumentListener)listeners[i + 1]).insertUpdate(e);
- }
- }
-
- }
-
- protected void fireRemoveUpdate(DocumentEvent e) {
- Object[] listeners = this.listenerList.getListenerList();
-
- for(int i = listeners.length - 2; i >= 0; i -= 2) {
- Object var10000 = listeners[i];
- Class var10001 = class$com$sun$java$swing$event$DocumentListener;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("com.sun.java.swing.event.DocumentListener");
- } catch (ClassNotFoundException var4) {
- throw new NoClassDefFoundError(((Throwable)var4).getMessage());
- }
-
- class$com$sun$java$swing$event$DocumentListener = var10001;
- }
-
- if (var10000 == var10001) {
- ((DocumentListener)listeners[i + 1]).removeUpdate(e);
- }
- }
-
- }
-
- protected void fireUndoableEditUpdate(UndoableEditEvent e) {
- Object[] listeners = this.listenerList.getListenerList();
-
- for(int i = listeners.length - 2; i >= 0; i -= 2) {
- Object var10000 = listeners[i];
- Class var10001 = class$com$sun$java$swing$event$UndoableEditListener;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("com.sun.java.swing.event.UndoableEditListener");
- } catch (ClassNotFoundException var4) {
- throw new NoClassDefFoundError(((Throwable)var4).getMessage());
- }
-
- class$com$sun$java$swing$event$UndoableEditListener = var10001;
- }
-
- if (var10000 == var10001) {
- ((UndoableEditListener)listeners[i + 1]).undoableEditHappened(e);
- }
- }
-
- }
-
- protected final AttributeContext getAttributeContext() {
- return this.context;
- }
-
- protected final Content getContent() {
- return this.data;
- }
-
- protected final synchronized Thread getCurrentWriter() {
- return this.currWriter;
- }
-
- public abstract Element getDefaultRootElement();
-
- public Dictionary getDocumentProperties() {
- if (this.documentProperties == null) {
- this.documentProperties = new Hashtable(2);
- }
-
- return this.documentProperties;
- }
-
- public final Position getEndPosition() {
- Position p;
- try {
- p = this.createPosition(this.data.length());
- } catch (BadLocationException var2) {
- p = null;
- }
-
- return p;
- }
-
- public int getLength() {
- return this.data.length() - 1;
- }
-
- public final Object getProperty(Object key) {
- return this.getDocumentProperties().get(key);
- }
-
- public Element[] getRootElements() {
- Element[] elems = new Element[1];
- elems[0] = this.getDefaultRootElement();
- return elems;
- }
-
- public final Position getStartPosition() {
- Position p;
- try {
- p = this.createPosition(0);
- } catch (BadLocationException var2) {
- p = null;
- }
-
- return p;
- }
-
- public String getText(int offset, int length) throws BadLocationException {
- String str = this.data.getString(offset, length);
- return str;
- }
-
- public void getText(int offset, int length, Segment txt) throws BadLocationException {
- this.data.getChars(offset, length, txt);
- }
-
- public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
- if (str != null && str.length() != 0) {
- try {
- this.writeLock();
- UndoableEdit u = this.data.insertString(offs, str);
- DefaultDocumentEvent e = new DefaultDocumentEvent(this, offs, str.length(), EventType.INSERT);
- if (u != null) {
- e.addEdit(u);
- }
-
- this.insertUpdate(e, a);
- ((CompoundEdit)e).end();
- this.fireInsertUpdate(e);
- if (u != null) {
- this.fireUndoableEditUpdate(new UndoableEditEvent(this, e));
- }
- } finally {
- this.writeUnlock();
- }
-
- }
- }
-
- protected void insertUpdate(DefaultDocumentEvent chng, AttributeSet attr) {
- }
-
- public final void putProperty(Object key, Object value) {
- if (value != null) {
- this.getDocumentProperties().put(key, value);
- } else {
- this.getDocumentProperties().remove(key);
- }
-
- }
-
- protected final synchronized void readLock() {
- try {
- while(true) {
- if (this.currWriter != null) {
- this.wait();
- } else {
- ++this.numReaders;
- break;
- }
- }
- } catch (InterruptedException var1) {
- }
-
- }
-
- private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
- s.defaultReadObject();
- this.listenerList = new EventListenerList();
- }
-
- protected final synchronized void readUnlock() {
- if (this.numReaders <= 0) {
- throw new StateInvariantError("document lock failure");
- } else {
- --this.numReaders;
- this.notify();
- }
- }
-
- public void remove(int offs, int len) throws BadLocationException {
- if (len > 0) {
- try {
- this.writeLock();
- DefaultDocumentEvent chng = new DefaultDocumentEvent(this, offs, len, EventType.REMOVE);
- this.removeUpdate(chng);
- UndoableEdit u = this.data.remove(offs, len);
- if (u != null) {
- chng.addEdit(u);
- }
-
- ((CompoundEdit)chng).end();
- this.fireRemoveUpdate(chng);
- if (u != null) {
- this.fireUndoableEditUpdate(new UndoableEditEvent(this, chng));
- }
- } finally {
- this.writeUnlock();
- }
- }
-
- }
-
- public void removeDocumentListener(DocumentListener listener) {
- EventListenerList var10000 = this.listenerList;
- Class var10001 = class$com$sun$java$swing$event$DocumentListener;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("com.sun.java.swing.event.DocumentListener");
- } catch (ClassNotFoundException var2) {
- throw new NoClassDefFoundError(((Throwable)var2).getMessage());
- }
-
- class$com$sun$java$swing$event$DocumentListener = var10001;
- }
-
- var10000.remove(var10001, listener);
- }
-
- public void removeUndoableEditListener(UndoableEditListener listener) {
- EventListenerList var10000 = this.listenerList;
- Class var10001 = class$com$sun$java$swing$event$UndoableEditListener;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("com.sun.java.swing.event.UndoableEditListener");
- } catch (ClassNotFoundException var2) {
- throw new NoClassDefFoundError(((Throwable)var2).getMessage());
- }
-
- class$com$sun$java$swing$event$UndoableEditListener = var10001;
- }
-
- var10000.remove(var10001, listener);
- }
-
- protected void removeUpdate(DefaultDocumentEvent chng) {
- }
-
- public void render(Runnable r) {
- try {
- this.readLock();
- r.run();
- } finally {
- this.readUnlock();
- }
-
- }
-
- public void setDocumentProperties(Dictionary x) {
- this.documentProperties = x;
- }
-
- protected final synchronized void writeLock() {
- try {
- while(this.numReaders > 0 || this.currWriter != null) {
- this.wait();
- }
-
- this.currWriter = Thread.currentThread();
- } catch (InterruptedException var1) {
- }
-
- }
-
- protected final synchronized void writeUnlock() {
- if (this.numReaders <= 0 && this.currWriter != null) {
- this.currWriter = null;
- this.notify();
- } else {
- throw new StateInvariantError("document lock failure");
- }
- }
- }
-